<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @copyright   Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
/* @var $this \Magento\Catalog\Block\Product\Compare\ListCompare */
?>
<?php $_total = $this->getItems()->getSize() ?>
<?php if($_total): ?>
    <a href="#" class="action print" title="<?php echo __('Print This Page') ?>">
        <span><?php echo __('Print This Page') ?></span>
    </a>
    <?php $imageBlock =  $this->getLayout()->createBlock('Magento\Catalog\Block\Product\Image'); ?>
        <div class="table-wrapper comparison">
            <table class="data table table-comparison" id="product-comparison"
                data-mage-init='{"compareList":{
                    "windowPrintSelector":".action.print",
                    "productsInRow":"5",
                    "selectors":{
                        "productAddToCartSelector":"button.action.tocart"}
                }}'>
                <caption><?php echo __('Compare Products') ?></caption>
                <thead>
                <tr>
                    <?php $_i=0 ?>
                    <?php foreach($this->getItems() as $_item): ?>
                        <?php if($_i++==0): ?>
                            <th scope="row" class="cell label remove"><span><?php echo __('Remove Product') ?></span></th>
                        <?php endif; ?>
                        <td class="cell remove product">
                            <?php $compareHelper = $this->helper('Magento\Catalog\Helper\Product\Compare');?>
                            <a href="#" data-post='<?php echo $compareHelper->getPostDataRemove($_item); ?>'
                               class="action delete" title="<?php echo __('Remove Product') ?>">
                                <span><?php echo __('Remove Product') ?></span>
                            </a>
                        </td>
                    <?php endforeach; ?>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <?php $_i = 0; ?>
                    <?php $_helper = $this->helper('Magento\Catalog\Helper\Output'); ?>
                    <?php /** @var $_item \Magento\Catalog\Model\Product */ ?>
                    <?php foreach($this->getItems() as $_item): ?>
                        <?php if($_i++==0): ?>
                            <th scope="row" class="cell label product"><span><?php echo __('Product') ?></span></th>
                        <?php endif; ?>
                        <td class="cell product info">
                            <a class="product-item-photo" href="<?php echo $this->getProductUrl($_item) ?>" title="<?php echo $this->stripTags($_item->getName(), null, true) ?>">
                                <?php /* product_comparison_list */ ?>
                                <?php echo $imageBlock->init($_item, 'product_comparison_list')->toHtml() ?>
                            </a>
                            <strong class="product-item-name">
                                <a href="<?php echo $this->getProductUrl($_item) ?>" title="<?php echo $this->stripTags($_item->getName(), null, true) ?>">
                                    <?php echo $_helper->productAttribute($_item, $_item->getName(), 'name') ?>
                                </a>
                            </strong>
                            <?php echo $this->getReviewsSummaryHtml($_item, 'short') ?>
                            <?php echo $this->getProductPrice($_item, '-compare-list-top') ?>
                            <div class="product-item-actions">
                                <div class="actions-primary">
                                    <?php if($_item->isSaleable()): ?>
                                        <button type="button" class="action tocart primary"
                                                data-url="<?php echo $this->helper('Magento\Catalog\Helper\Product\Compare')->getAddToCartUrl($_item) ?>">
                                            <span><?php echo __('Add to Cart') ?></span>
                                        </button>
                                    <?php else: ?>
                                        <?php if ($_item->getIsSalable()): ?>
                                            <p class="stock available"><span><?php echo __('In stock') ?></span></p>
                                        <?php else: ?>
                                            <p class="stock unavailable"><span><?php echo __('Out of stock') ?></span></p>
                                        <?php endif; ?>
                                    <?php endif; ?>
                                </div>
                                <?php if ($this->helper('Magento\Wishlist\Helper\Data')->isAllow()) : ?>
                                    <div class="secondary-addto-links actions-secondary" data-role="add-to-links">
                                        <a href="#" data-post='<?php echo $this->getAddToWishlistParams($_item); ?>' class="action towishlist" data-action="add-to-wishlist">
                                            <span><?php echo __('Add to Wishlist') ?></span>
                                        </a>
                                    </div>
                                <?php endif; ?>
                            </div>
                        </td>
                    <?php endforeach; ?>
                </tr>
                </tbody>
                <tbody>
                <?php foreach ($this->getAttributes() as $_attribute): ?>
                    <tr>
                        <?php $_i = 0 ?>
                        <?php foreach($this->getItems() as $_item): ?>
                            <?php if($_i++==0): ?>
                                <th scope="row" class="cell label">
                                    <span class="attribute label">
                                        <?php echo $this->escapeHtml($_attribute->getStoreLabel() ? $_attribute->getStoreLabel() : __($_attribute->getFrontendLabel())) ?>
                                    </span>
                                </th>
                            <?php endif; ?>
                            <td class="cell product attribute">
                                <div class="attibute value">
                                    <?php switch ($_attribute->getAttributeCode()) {
                                        case "price": ?>
                                            <?php
                                                echo $this->getProductPrice(
                                                    $_item,
                                                    '-compare-list-' . $_attribute->getCode()
                                                )
                                            ?>
                                            <?php break;
                                        case "small_image": ?>
                                            <img src="<?php echo $this->getSmallImageUrl($_item); ?>"
                                                 width="<?php echo $this->getSmallImageSize() ?>"
                                                 height="<?php echo $this->getSmallImageSize() ?>"
                                                 alt="<?php echo $this->stripTags($_item->getName(), null, true) ?>"/>
                                            <?php break;
                                        default: ?>
                                        <?php echo $_helper->productAttribute($_item, $this->getProductAttributeValue($_item, $_attribute), $_attribute->getAttributeCode()) ?>
                                        <?php break;
                                    } ?>
                                </div>
                            </td>
                        <?php endforeach; ?>
                    </tr>
                <?php endforeach; ?>
                </tbody>
            </table>
        </div>
<?php else: ?>
    <p class="empty"><?php echo __('You have no items to compare.') ?></p>
<?php endif; ?>
